#include "SmokeObject.h"
int SmokeObject::smoke_name = 0;

bool SmokeObject::compiled = false;

SmokeObject::SmokeObject()
{
}

SmokeObject::~SmokeObject(){}


void SmokeObject::LoadLists()
{
 smoke_name = glGenLists(1); 

 //disegno il fumo
glNewList(smoke_name,GL_COMPILE);
        glDisable(GL_DEPTH_TEST);
        glColor4f(0.50f, 1.0f, 1.0f, 0.4);     
        glBlendFunc(GL_SRC_ALPHA,GL_ONE);       
        glEnable(GL_BLEND);         
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D,state->th->texNames[TEX_SMOKE]);
        
        glBegin(GL_QUADS);
              glTexCoord2f(0.0f, 1.0f);   glVertex3f(-2,-2,0);
              glTexCoord2f(0.0f, 0.0f);   glVertex3f(-2,2,0);
              glTexCoord2f(1.0f, 0.0f);   glVertex3f(2,2,0 );
              glTexCoord2f(1.0f, 1.0f);   glVertex3f(2,-2,0 );
        glEnd();
         glEnable(GL_DEPTH_TEST);
        glDisable(GL_TEXTURE_2D);
        glDisable(GL_BLEND);  
        
glEndList();
compiled = true;
}

void SmokeObject::DoIdle()
{
    dy_fum += 0.2;
    scale_x += 0.05;
    scale_y -= 0.01;
    
    if (scale_y < 0.3) visible = false;
}

void SmokeObject::Init()
{
    //incremento altezza e scalatura per il fumo
    dy_fum = 0;
    scale_y = 1.0;
    scale_x = 1.0;
    visible = true;
    scale = 1.0;
    if (!compiled) LoadLists();
}




void SmokeObject::Draw()
{
       //disegno la nuvoletta di fumo in partenza
 glPushMatrix();
        glTranslatef(pos.x,pos.y + dy_fum,pos.z);            //riporto nelle coordinate dell'elicottero
        glRotatef(-state->cam_angY,0,1,0);
        glScalef(scale_x*scale,scale_y*scale,1);
        glCallList(smoke_name);

glPopMatrix();
}
